/* eslint-disable */
let id = 1000;
export default {
  data() {

    const generateData = _ => {
      const data = [];
      const alldata = ['立项','拆迁红线','场地移交','设计要点','测绘','土地挂牌','环评','勘察合同','施工图纸','土方工程','不动产权证','其他'];
      // data.push('征地拆迁','测绘','土地挂牌');
      for (let i = 0; i < alldata.length; i++) {
        data.push({
          key: i,
          label:alldata[i],
          // disabled: i % 4 === 0
        });
      }
      return data;
    };
    const data = [{
      id: 1,
      label: '征地拆迁',
      children: [{
        id: 4,
        label: '立项',
        children: [{
          id: 9,
          label: '立项前期'
        }, {
          id: 10,
          label: '立项后期'
        }]
      }]
    }, {
      id: 2,
      label: '土地挂牌',
      children: [{
        id: 5,
        label: '设计要点'
      }, {
        id: 6,
        label: '地价'
      }]
    }, {
      id: 3,
      label: '一级 3',
      children: [{
        id: 7,
        label: '二级 3-1'
      }, {
        id: 8,
        label: '二级 3-2'
      }]
    }];

    return {
      projectData: [{
        id: 0,
        label: '付款节点名称',
        startTime: '计划开始时间',
        endTime: '计划结束时间',
        actualStartTime: '实际开始时间',
        actualEndTime: '实际结束时间',
        plannedHours: '计划工时',
        precondition: '前置条件',
        responsibleDepartment: '责任部门',
        desc: '备注',
      },{
        id: 1,
        label: '立项',
        startTime: '2020-01-20',
        endTime: '2020-03-30',
        actualStartTime: '2020-01-20',
        actualEndTime: '2020-03-30',
        plannedHours: '2个月',
        precondition: '暂无条件',
        responsibleDepartment: '投资与人才促进部',
        desc: '工程备注信息',
        children: [{
          id: 2,
          label: '确定建设主体',
          startTime: '2020-01-20',
          endTime: '2020-03-30',
          actualStartTime: '2020-01-20',
          actualEndTime: '2020-03-30',
          plannedHours: '2个月',
          precondition: '暂无条件',
          responsibleDepartment: '规土局',
          desc: '',
          children: [{
            id: 4,
            label: '确定建设主体',
            startTime: '2020-01-20',
            endTime: '2020-03-30',
            actualStartTime: '2020-01-20',
            actualEndTime: '2020-03-30',
            plannedHours: '2个月',
            precondition: '暂无条件',
            responsibleDepartment: '规土局',
            desc: '',
            children: [{
              id: 6,
              label: '项目公司营业执照及公章',
              startTime: '2020-01-20',
              endTime: '2020-03-30',
              actualStartTime: '2020-01-20',
              actualEndTime: '2020-03-30',
              plannedHours: '2个月',
              precondition: '暂无条件',
              responsibleDepartment: '规土局',
              desc: '',
            }]
          }]
        }, {
          id: 3,
          label: '立项',
          startTime: '2020-01-20',
          endTime: '2020-03-30',
          actualStartTime: '2020-01-20',
          actualEndTime: '2020-03-30',
          plannedHours: '2个月',
          precondition: '暂无条件',
          responsibleDepartment: '规土局',
          desc: '',
          children: [{
            id: 5,
            label: '备案证',
            startTime: '2020-01-20',
            endTime: '2020-03-30',
            actualStartTime: '2020-01-20',
            actualEndTime: '2020-03-30',
            plannedHours: '2个月',
            precondition: '暂无条件',
            responsibleDepartment: '规土局',
            desc: '',
            children: [{
              id: 7,
              label: '科研',
              startTime: '2020-01-20',
              endTime: '2020-03-30',
              actualStartTime: '2020-01-20',
              actualEndTime: '2020-03-30',
              plannedHours: '2个月',
              precondition: '概念方案',
              responsibleDepartment: '规土局',
              desc: '',
            },
            {
              id: 8,
              label: '备案证',
              startTime: '2020-01-20',
              endTime: '2020-03-30',
              actualStartTime: '2020-01-20',
              actualEndTime: '2020-03-30',
              plannedHours: '2个月',
              precondition: '可研',
              responsibleDepartment: '规土局',
              desc: '',
            }]
          }]
        }]
      }, {
        id: 9,
        label: '土地挂牌',
        startTime: '2020-01-20',
        endTime: '2020-03-30',
        actualStartTime: '2020-01-20',
        actualEndTime: '2020-03-30',
        plannedHours: '2个月',
        precondition: '暂无条件',
        responsibleDepartment: '规土部',
        desc: '',
        children: [{
          id: 10,
          label: '征地拆迁',
          startTime: '2020-01-20',
          endTime: '2020-03-30',
          actualStartTime: '2020-01-20',
          actualEndTime: '2020-03-30',
          plannedHours: '2个月',
          precondition: '暂无条件',
          responsibleDepartment: '规土部',
          desc: '',
          children: [{
            id: 11,
            label: '拆迁红线（勘测定界）',
            startTime: '2020-01-20',
            endTime: '2020-03-30',
            actualStartTime: '2020-01-20',
            actualEndTime: '2020-03-30',
            plannedHours: '2个月',
            precondition: '暂无条件',
            responsibleDepartment: '规土部',
            desc: '',
            children: [{
              id: 14,
              label: '调查',
              startTime: '2020-01-20',
              endTime: '2020-03-30',
              actualStartTime: '2020-01-20',
              actualEndTime: '2020-03-30',
              plannedHours: '2个月',
              precondition: '暂无条件',
              responsibleDepartment: '规土部',
              desc: '',
            }, {
              id: 15,
              label: '拆迁红线（勘测定界）',
              startTime: '2020-01-20',
              endTime: '2020-03-30',
              actualStartTime: '2020-01-20',
              actualEndTime: '2020-03-30',
              plannedHours: '2个月',
              precondition: '暂无条件',
              responsibleDepartment: '规土部',
              desc: '',
            }]
          }, {
            id: 12,
            label: '拆迁协议',
            startTime: '2020-01-20',
            endTime: '2020-03-30',
            actualStartTime: '2020-01-20',
            actualEndTime: '2020-03-30',
            plannedHours: '2个月',
            precondition: '暂无条件',
            responsibleDepartment: '规土部',
            desc: '',
            children: [{
              id: 16,
              label: '拆迁评估',
              startTime: '2020-01-20',
              endTime: '2020-03-30',
              actualStartTime: '2020-01-20',
              actualEndTime: '2020-03-30',
              plannedHours: '2个月',
              precondition: '暂无条件',
              responsibleDepartment: '规土部',
              desc: '',
            }, {
              id: 17,
              label: '拆迁协议',
              startTime: '2020-01-20',
              endTime: '2020-03-30',
              actualStartTime: '2020-01-20',
              actualEndTime: '2020-03-30',
              plannedHours: '2个月',
              precondition: '暂无条件',
              responsibleDepartment: '规土部',
              desc: '',
            }]
          }, {
            id: 13,
            label: '场地移交',
            startTime: '2020-01-20',
            endTime: '2020-03-30',
            actualStartTime: '2020-01-20',
            actualEndTime: '2020-03-30',
            plannedHours: '2个月',
            precondition: '暂无条件',
            responsibleDepartment: '规土部',
            desc: '',
            children: [{
              id: 18,
              label: '拆迁队伍',
              startTime: '2020-01-20',
              endTime: '2020-03-30',
              actualStartTime: '2020-01-20',
              actualEndTime: '2020-03-30',
              plannedHours: '2个月',
              precondition: '暂无条件',
              responsibleDepartment: '规土部',
              desc: '',
            }, {
              id: 19,
              label: '场地移交',
              startTime: '2020-01-20',
              endTime: '2020-03-30',
              actualStartTime: '2020-01-20',
              actualEndTime: '2020-03-30',
              plannedHours: '2个月',
              precondition: '暂无条件',
              responsibleDepartment: '规土部',
              desc: '',
            }]
          }]
        }]
      }],
       // 部门列表
       departmentList: [
        '投资与人才促进部',
        '规土部',
        '财务部',
        '工程部',
      ],
        // 新增项目节点
        appendNode: {
          title: '合同录入',
          status: false,
        },
        // 父级节点
        fatherNode: {},
        // 节点表单
        appendNodeFrom: {
          name:'合同名称',
          id:'',
          timeValue:'',
          moneynum:'',
          label: '立项', // 节点名称
          startTime: '2020-01-20', // 计划开始时间
          actualStartTime: '2020-01-20', // 实际开始时间
          actualEndTime: '2020-03-30', // 实际结束时间
          plannedHours: '2个月', // 计划工时
          precondition: '暂无条件', // 前置条件
          responsibleDepartment: '投资与人才促进部', // 责任部门
          desc: '工程备注信息' // 备注
        },
        // timeValue: ['2020-01-20', '2020-03-30'],
        // timeValueActual: ['2020-01-20', '2020-03-30'],
        // 验证
        appendNodeRules: {
          label: [
            { required: true, message: '请输入付款项', trigger: 'blur' },
          ],
          id: [
            { required: true, message: '请输入合同ID', trigger: 'blur' },
          ],
          name: [
            { required: true, message: '请输入付款节点名称', trigger: 'blur' },
          ],

          responsibleDepartment:[
            { required: true, message: '请输入责任部门', trigger: 'blur' },
          ],

          plannedHours:[
            { required: true, message: '请输入付款方', trigger: 'blur' },
          ],
          timeValue:[
            { required: true, message: '请输入时间', trigger: 'blur' },
          ],
          precondition:[
            { required: true, message: '请输入收款方', trigger: 'blur' },
          ],
          moneynum:[
            { required: true, message: '请输入交易金额', trigger: 'blur' },
          ],
          desc:[
            { required: true, message: '请选择合同', trigger: 'blur' },
          ],
        },
      data: JSON.parse(JSON.stringify(data)),
      data: JSON.parse(JSON.stringify(data)),
      tempData: generateData(),
      value: [],
      // 模板数据
      companyData:[
        {
          contractNo: '0001201911025861',
          assetName: 'xxx项目1',
          assetType: '10亿',
          assetLevel: '15',
          statistics: '5',
          startTime:'2019-3-1',
          endTime: '2022-3-1'

        },
        {
          contractNo: '0001201911025031',
          assetName: 'xxx项目2',
          assetType: '15亿',
          assetLevel: '13',
          statistics: '5',
          startTime:'2019-10-1',
          endTime: '2024-3-1'

        },
        {
          contractNo: '0001201911025031',
          assetName: 'xxx项目3',
          assetType: '8亿',
          assetLevel: '18',
          statistics: '5',
          startTime: '2020-7-1',
          endTime: '2024-7-1'
        },
        {
          contractNo: '0001201911024234',
          assetName: 'xxx项目4',
          assetType: '8亿',
          assetLevel: '18',
          statistics: '5',
          startTime: '2020-5-1',
          endTime: '2022-5-1',
          construction: 'xxx公司',

        }
        ,{
          contractNo: '0001201911024234',
          assetName: 'xxx项目5',
          assetType: '20亿',
          assetLevel: '14',
          statistics: '7',
          startTime: '2019-4-1',
          endTime: '2022-4-1',
          construction: 'xxx公司'
        }
      ],

      // '新增模板'弹窗
      dialogCompany:{
        title: '新增项目',
        status: false,
      },

      // ‘新增模板’表单数据
      companyFrom:{
        companyName: '',
        companyContact: '',
        companyTel: '',
        requisitionLimit: '',
        restrictedType: '',
        repairAssetType: '',
        restrictedType1:''
      },

      // '新增项目'表单验证
      companyRules: {
        companyName: [
          { required: true, message: '请输入模板名称', trigger: 'blur' },
        ],
        companyContact: [
          { required: true, message: '请输入创建人', trigger: 'blur' },
        ],
        companyTel: [
          { required: true, message: '请选择项目类别', trigger: 'blur' },
        ],
        requisitionLimit: [
          { required: true, message: '请选择专项', trigger: 'blur' },
        ],
        restrictedType: [
          { required: true, message: '请选择创建时间', trigger: 'blur' },
        ],
        restrictedType1: [
          { required: true, message: '请选择任务节点', trigger: 'blur' },
        ]
      },
      //'查看模板'弹窗
      looktemplate:{
        title: '查看项目详情',
        status: false,
      },
      //‘查看项目详情’表单数据
      lookForm:{
        contractNo: '',
        assetName: '',
        assetType: '',
        assetLevel: '',
        startTime: '',
        endTime: '',
        construction: '',
        statistics:'',
        investment:'',
        legalUnit:'',
        site:'',
        plate:'',
        task1:'',
        task2:'',
        task3:'',
        task4:''
      },
      //'查看模板'数据
      lookdata:[
        {
        contractNo: '0001201911025861',
        assetName: 'xxx项目1',
        assetType: '服务业',
        assetLevel: '市级',
        startTime: '2020-3-1',
        endTime: '2022-3-1',
        construction: 'xxx公司',
        statistics:'是',
        investment:'50亿',
        legalUnit:'研创园',
        site:'研创园东',
        plate:'**板块',
        task1:'勘测定界红线',
        task2:'设计要点',
        task3:'勘测定界成果',
        task4:'地灾评估',
        task5:'...'
        },
        //
      ],
      //修改模板弹窗
      updatetemplate:{
        title: '修改模板',
        status: false,
      },
      // 查看弹窗
      showemplate:{
        title: '新增合同',
        status: false,
      },
      // ‘修改模板’表单数据
      updateFrom:{
        companyName: '',
        companyContact: '',
        companyTel: '',
        requisitionLimit: '',
        restrictedType: '',
        repairAssetType: '',
      },
    }
  },
  mounted() {
  },
  methods: {
    // 新增模板弹窗
    dialogCompanyOpen(row){
      console.log(row.companyName)
      if(row.companyName == undefined){
        this.dialogCompany.title = '新增项目'
        this.resetCompany()
      }else{
        this.dialogCompany.title = '更新模板'
        this.companyFrom = row
      }
      this.dialogCompany.status = true
    },
    //修改模板弹窗
    updateTemplateOpen(row){
      console.log(row.companyName)
      if(row.companyName == undefined){
        this.dialogCompany.title = '修改模板'
        this.resetCompany()
      }else{
        this.dialogCompany.title = '修改模板'
        this.companyFrom = row
      }
      this.dialogCompany.status = true
    },
    //查看模板弹窗
    lookTemplateOpen(row){
      console.log(row.id)
      if(row.id == undefined){
        this.looktemplate.title = '查看模板'
      }else{
        this.looktemplate.title = '查看模板'
        this.lookForm = row
      }
      this.looktemplate.status = true
    },

    handleChange(value, direction, movedKeys) {
      console.log(value, direction, movedKeys);
    },

    // 新增模板
    addCompany(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$message({
            type: 'success',
            message: '新增成功!'
          })
          this.dialogCompany.status = false
        } else {
          this.$message({
            type: 'warning',
            message: '请填写相关信息!'
          })
          return false;
        }
      });
    },

    // 重置新增模板表单
    resetCompany() {
      this.companyFrom = {
        companyName: '',
        companyContact: '',
        companyTel: '',
        requisitionLimit: '',
        restrictedType: '',
        repairAssetType: '',
      }
    },

    // 删除模板
    delCompany(row){
      this.$confirm('正在删除'+  row.companyName  +'公司, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    append(data) {
      const newChild = { id: id++, label: 'testtest', children: [] };
      if (!data.children) {
        this.$set(data, 'children', []);
      }
      data.children.push(newChild);
    },

    remove(node, data) {
      const parent = node.parent;
      const children = parent.data.children || parent.data;
      const index = children.findIndex(d => d.id === data.id);
      children.splice(index, 1);
    },

    renderContent(h, { node, data, store }) {
      return (
        <span class="custom-tree-node">
          <span>{node.label}</span>
          <span>
            <el-button size="mini" type="text" on-click={ () => this.append(data) }>Append</el-button>
            <el-button size="mini" type="text" on-click={ () => this.remove(node, data) }>Delete</el-button>
          </span>
        </span>);
    },
    // 重置节点信息
    resetNode() {
      this.appendNodeFrom = {
        label: '', // 节点名称
        startTime: '', // 计划开始时间
        endTime: '', // 计划结束时间
        actualStartTime: '', // 实际开始时间
        actualEndTime: '', // 实际结束时间
        plannedHours: '', // 计划工时
        precondition: '', // 前置条件
        responsibleDepartment: '', // 责任部门
        desc: '' // 备注
      }
    },

    // 查看节点详情
    nodeInfo(data) {
      this.resetNode()
      this.appendNodeFrom = data
      this.appendNode.status = true
      this.appendNode.title = '修改节点'
    },

    // 新增节点
    append(data) {
      this.timeValue = []
      this.timeValueActual = []
      this.fatherNode = {}
      this.fatherNode = data
      console.log(this.fatherNode)
      this.resetNode()
      this.appendNode.status = true
    },
    // 新增节点提交
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.appendNodeFrom.id = id++
          this.appendNodeFrom.children = []
          if (!this.fatherNode.children) {
            this.$set(this.fatherNode, 'children', []);
          }
          this.fatherNode.children.push(this.appendNodeFrom);
          this.appendNode.status = false
        } else {
          return false;
        }
      });
    },
    // 分离日期
    separateTime(type) {
      console.log(this.timeValue)
      console.log(this.timeValueActual)
      console.log(type)
      if (type == 0) {
        this.appendNodeFrom.startTime = this.timeValue[0]
        this.appendNodeFrom.endTime = this.timeValue[1]
      } else {
        this.appendNodeFrom.actualStartTime = this.timeValueActual[0]
        this.appendNodeFrom.actualEndTime = this.timeValueActual[1]
      }
    },

    // 更新节点
    updateNode() {
      this.$message({
        message: '节点已更新',
        type: 'success'
      });
    },

    // 删除节点
    remove(node, data) {
      this.$confirm('此操作会删除该节点下所有子节点, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
        const parent = node.parent;
        const children = parent.data.children || parent.data;
        const index = children.findIndex(d => d.id === data.id);
        children.splice(index, 1);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

  }
}
